package site.yunnong.atvris.common.enumeration;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author zjh
 * @date 2021/9/8 20:16
 */
public enum RankTypeEnum {
    
    HOT_DEGREE(0, "热度排序", "score"),
    TIME(1, "创建时间排序", "create_time"),
    VIEW_COUNT(2, "播放次数排序", "view_count"),
    STAR_COUNT(3, "收藏量排序", "star_count"),
    CLICK_COUNT(4, "点击量排序", "click_count"),
    FANS_COUNT(5, "粉丝数排序", "fans_count"),
    LEVEL(6, "积分排序", "growth");
    
    private Integer value;
    
    private String desc;
    
    private String field;
    
    RankTypeEnum(Integer value, String desc, String field) {
        this.value = value;
        this.desc = desc;
        this.field = field;
    }

    public Integer getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    public String getField() {
        return field;
    }

    /**
     * 根据排序规则获取排序字段
     * @param value
     * @return
     */
    public static String getFieldByValue(Integer value) {
        List<RankTypeEnum> collect = Arrays.stream(RankTypeEnum.values())
                .filter(item -> item.getValue().equals(value))
                .collect(Collectors.toList());
        // 找到一个
        return Optional.of(collect).orElse(null).get(0).getField();
    }
}
